package org.bsscheduler;

import java.util.Hashtable;

/**
 * Static class for managing the list of users who are logged in
 * @author tblackstone
 */
public class UserManager {

    private static Hashtable<String, User> users = new Hashtable<String, User>();

    public static void addUser(User user) {
        users.put(user.getEmail(), user);
    }

    public static void removeUser(User user) {
        if (user.getLoggedIn()) {
            users.remove(user.getEmail());
        }
    }

    public static boolean userIsLoggedIn(String username) {
        return users.containsKey(username);
    }

    /**
     * Returns the User object for a given username
     * @param username the user to look up
     * @return the User object of the given user, or null if the user is
     * not logged in
     */
    public static User getUser(String username) {
        return users.get(username);
    }

}
